package com.yummy.cloud.gateway.manage.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.gateway.route.RouteDefinition;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.yummy.cloud.gateway.manage.dto.RouteDefinitionQuery;
import com.yummy.cloud.gateway.manage.service.RouteDefinitionService;
import com.yummy.convention.http.Response;
import com.yummy.convention.page.Pagination;

@RestController
@RequestMapping("/route")
public class RouteDefinitionController {
	
	@Autowired
	private RouteDefinitionService routeDefinitionService;

	@GetMapping("/list")
	public Response<Pagination<RouteDefinition>> list(RouteDefinitionQuery query){
		return Response.success(routeDefinitionService.getRouteDefinitions(query));
	}
	
	@PostMapping("/create")
	public Response<Boolean> create(@RequestBody RouteDefinition route){
		return Response.success(routeDefinitionService.create(route));
	}
	
	@PostMapping("/update")
	public Response<Boolean> update(@RequestBody RouteDefinition route){
		return Response.success(routeDefinitionService.update(route));
	}
	
	@GetMapping("/delete")
	public Response<Boolean> save(String routeId){
		return Response.success(routeDefinitionService.delete(routeId));
	}
	
}
